package com.fly.platform.base.pojo.elasticsearch


import com.fasterxml.jackson.annotation.JsonFormat
import com.fly.platform.common.constant.CommonConstant
import com.fly.platform.common.utils.SnowFlakeUtil
import io.swagger.annotations.ApiModelProperty
import org.springframework.data.annotation.Id
import org.springframework.data.elasticsearch.annotations.DateFormat
import org.springframework.data.elasticsearch.annotations.Document
import org.springframework.data.elasticsearch.annotations.Field
import org.springframework.data.elasticsearch.annotations.FieldType
import java.io.Serializable
import java.util.*


/**
 * Elasticsearch文档实体类
 * @author fly
 */
@Document(indexName = "log", type = "log", shards = 1, replicas = 0, refreshInterval = "-1")
data class EsLog(

        @Id
        @ApiModelProperty(value = "唯一标识")
        val id: String? = SnowFlakeUtil.nextId().toString(),

        @ApiModelProperty(value = "创建者")
        val createBy: String? = null,

        @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
        @ApiModelProperty(value = "创建时间")
        @Field(type = FieldType.Date, index = false, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
        val createTime: Date = Date(),

        @ApiModelProperty(value = "时间戳 查询时间范围时使用")
        val timeMillis: Long = System.currentTimeMillis(),

        @ApiModelProperty(value = "更新者")
        val updateBy: String? = null,

        @ApiModelProperty(value = "删除标志 默认0")
        val delFlag: Int = CommonConstant.STATUS_NORMAL,

        @ApiModelProperty(value = "方法操作名称")
        var name: String? = null,

        @ApiModelProperty(value = "日志类型 0登陆日志 1操作日志")
        val logType: Int? = null,

        @ApiModelProperty(value = "请求路径")
        var requestUrl: String? = null,

        @ApiModelProperty(value = "请求类型")
        var requestType: String? = null,

        @ApiModelProperty(value = "请求参数")
        var requestParam: String? = null,

        @ApiModelProperty(value = "请求用户")
        var username: String? = null,

        @ApiModelProperty(value = "ip")
        val ip: String? = null,

        @ApiModelProperty(value = "ip信息")
        val ipInfo: String? = null,

        @ApiModelProperty(value = "花费时间")
        var costTime: Int? = null

) : Serializable {

    companion object {
         const val serialVersionUID = 1L
    }
}